package com.yuanyu.server.impl;

import com.yuanyu.common.util.AssertUtil;
import com.yuanyu.common.util.CopyUtil;
import com.yuanyu.mapper.mysqlMapper.Dry_pump_unit_assembly_record.Dry_pump_unit_assembly_record_1_Mapper;
import com.yuanyu.mapper.mysqlMapper.Dry_pump_unit_assembly_record.Dry_pump_unit_assembly_record_Mapper;
import com.yuanyu.mapper.mysqlMapper.MainTable_Mapper;
import com.yuanyu.model.dto.Dry_pump_unit_assembly_recordDTO;
import com.yuanyu.model.entity.Dry_pump_unit_assembly_record.Dry_pump_unit_assembly_record;
import com.yuanyu.model.entity.Dry_pump_unit_assembly_record.Dry_pump_unit_assembly_record_1;
import com.yuanyu.model.vo.Dry_pump_unit_assembly_recordVO;
import com.yuanyu.server.ITestPart8Server;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

@Service
@Transactional
public class TestPart8ServerImpl implements ITestPart8Server {
    @Autowired
    private Dry_pump_unit_assembly_record_Mapper dryPumpUnitAssemblyRecordMapper;
    @Autowired
    private Dry_pump_unit_assembly_record_1_Mapper dryPumpUnitAssemblyRecord1Mapper;
    @Autowired
    private MainTable_Mapper mainTableMapper;

    @Override
    public String test() {
        return "测试成功";
    }

    @Override
    public String test8(Dry_pump_unit_assembly_recordVO dryPumpUnitAssemblyRecordVO) {
        Dry_pump_unit_assembly_record test = dryPumpUnitAssemblyRecordMapper.selTableTime(dryPumpUnitAssemblyRecordVO.getInput_Case());
        AssertUtil.isNull(test,"Case已存在,如需修改内容请前往后台修改");

        Dry_pump_unit_assembly_record dryPumpUnitAssemblyRecord = new Dry_pump_unit_assembly_record();
        Dry_pump_unit_assembly_record_1 dryPumpUnitAssemblyRecord1 = new Dry_pump_unit_assembly_record_1();

        CopyUtil.copyClass(dryPumpUnitAssemblyRecordVO,dryPumpUnitAssemblyRecord);
        dryPumpUnitAssemblyRecord.setCreatedAt(LocalDateTime.now());
        dryPumpUnitAssemblyRecord.setUpdatedAt(LocalDateTime.now());
        CopyUtil.copyClass(dryPumpUnitAssemblyRecordVO,dryPumpUnitAssemblyRecord1);

        System.out.println(dryPumpUnitAssemblyRecord);
        System.out.println(dryPumpUnitAssemblyRecord1);

        int i = dryPumpUnitAssemblyRecordMapper.addTableTime(dryPumpUnitAssemblyRecord);
        int i1 = dryPumpUnitAssemblyRecord1Mapper.addTable1(dryPumpUnitAssemblyRecord1);

        AssertUtil.isTrue(i == 1 && i1 == 1,"添加数据出现异常,请检查");
        mainTableMapper.updateByCaseFormStartTime(dryPumpUnitAssemblyRecordVO.getInput_Case());
        return "添加成功";
    }

    @Override
    public String updateTable8(Dry_pump_unit_assembly_recordVO dryPumpUnitAssemblyRecordVO) {
        Dry_pump_unit_assembly_record dryPumpUnitAssemblyRecord = new Dry_pump_unit_assembly_record();
        Dry_pump_unit_assembly_record_1 dryPumpUnitAssemblyRecord1 = new Dry_pump_unit_assembly_record_1();

        CopyUtil.copyClass(dryPumpUnitAssemblyRecordVO,dryPumpUnitAssemblyRecord);
        dryPumpUnitAssemblyRecord.setUpdatedAt(LocalDateTime.now());
        CopyUtil.copyClass(dryPumpUnitAssemblyRecordVO,dryPumpUnitAssemblyRecord1);

        int i = dryPumpUnitAssemblyRecordMapper.updateTableTime(dryPumpUnitAssemblyRecord);
        int i1 = dryPumpUnitAssemblyRecord1Mapper.updateTable1(dryPumpUnitAssemblyRecord1);

        AssertUtil.isTrue(i == 1 && i1 == 1,"表8修改数据出现异常,请检查");
        return "修改成功";
    }

    @Override
    public Dry_pump_unit_assembly_recordDTO getTest8(String Case) {
        Dry_pump_unit_assembly_record dryPumpUnitAssemblyRecord = dryPumpUnitAssemblyRecordMapper.selTableTime(Case);
        if (dryPumpUnitAssemblyRecord == null)return null;
        Dry_pump_unit_assembly_record_1 dryPumpUnitAssemblyRecord1 = dryPumpUnitAssemblyRecord1Mapper.selTable1(Case);

        Dry_pump_unit_assembly_recordDTO dryPumpUnitAssemblyRecordDTO = new Dry_pump_unit_assembly_recordDTO();
        CopyUtil.copyClass(dryPumpUnitAssemblyRecord,dryPumpUnitAssemblyRecordDTO);
        CopyUtil.copyClass(dryPumpUnitAssemblyRecord1,dryPumpUnitAssemblyRecordDTO);
        return dryPumpUnitAssemblyRecordDTO;
    }
}
